/*
 递归
 */

#include <stdio.h>
#include <string>
#include <vector>
#include <queue>

using namespace std;
using std :: vector;



#pragma mark - 给定n对括号，编写一个函数来生成正确括号的所有组合。
vector<string>vec;

void backpath(int n,int x,int y,string tmp){
    if (y == n ) {
        vec.push_back(tmp);
        return;
    }
    if (x< n ) {
        backpath(n, x+1,y, tmp + '(');
    }
    if (y< n && x<y) {
        backpath(n ,x , y+1, tmp + ')');
    }
    
}

#pragma mark - 全排列
//https://blog.csdn.net/kkdd2013/article/details/52078717
//https://blog.csdn.net/flyxiao28/article/details/80514369
//调用     permuteRecur(num, 0, res, tempres);

void permuteRecur(vector<int> &num, int index, vector<vector<int>> &res ){
    if (index == num.size()) {
        res.push_back(num);
        return;
    }
    for (int i = index; i<num.size(); i++) {
        swap(num[index], num[i]);//依次固定在首位
         permuteRecur(num, index + 1, res);//对后面剩下的继续重复
        swap(num[index], num[i]);//复位,恢复原来的位置,
    }
    
}


#pragma mark - 给定一个含不同整数的集合，返回其所有的子集。
//https://blog.csdn.net/i_am_bird/article/details/78315794
//https://blog.csdn.net/yinglish_/article/details/52497930
void allSubsets(vector<int>&num, int start, vector<vector<int>> &res, vector<int>path){
    res.push_back(path);
    if (start > num.size()) {
        return;
    }
    
    for (int i = start; i<num.size(); i++) {
        path.push_back(num[i]);
        allSubsets(num, start + 1, res , path);
        path.pop_back();
    }
    
}



int main_recursion(int argc, const char * argv[]) {
    // insert code here...
    string kuohao = "";
    
    backpath(2, 0, 0, kuohao);
    
    return 0;
}
